package vip.meet.base;

import com.mysql.cj.jdbc.MysqlDataSource;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.TransactionFactory;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.junit.jupiter.api.Test;
import vip.meet.dao.mapper.user.UserBeanMapper;

import java.util.List;

public class BuildSqlSessionFactory {
    
    private MysqlDataSource druidDataSource;
    
    @Test
    public void testBuildSqlSessionFactory(){
        TransactionFactory transactionFactory = new JdbcTransactionFactory();
        Environment environment =  new Environment("development", transactionFactory, druidDataSource); 
        Configuration configuration = new Configuration(environment); 
        configuration.addMapper(UserBeanMapper.class);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        List<Object> results = sqlSession.selectList("cn.freemethod.dao.mapper.info.TablesMapper.getTables");
        for(Object o:results){
            System.out.println(o);
        }
    }
    

    public void setUp(){
        druidDataSource = new MysqlDataSource();
        druidDataSource.setUser("tim");
        druidDataSource.setPassword("123456");
//        druidDataSource.set("com.mysql.jdbc.Driver");
        druidDataSource.setUrl("jdbc:mysql://127.0.0.1:3306/information_schema?useUnicode=true&characterEncoding=utf-8");
    }

}
